<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>住户列表</title>
	<link rel="stylesheet" type="text/css" href="../common/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="../common/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="../common/demo.css">
	<script type="text/javascript" src="../common/jquery.min.js"></script>
	<script type="text/javascript" src="../common/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../common/common.js"></script>
	<script type="text/javascript" src="../common/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>

<table id="dg" title="住户列表" style="width: 99%;height:630px"
	   data-options="rownumbers:true,
						singleSelect:true,
						autoRowHeight:true,
						pagination:true,
						pageSize:20,
						url:'/manage/user/userList',
						method:'get',
						toolbar:'#tb'">
	<thead>
	<tr>
		<th data-options="field:'userId',width:100,hidden:'true'">用户id</th>
		<th data-options="field:'platForm',width:100">用户账号</th>
		<th data-options="field:'userName',width:100">用户姓名</th>
		<th data-options="field:'sex',width:100">性别</th>
		<th data-options="field:'address',width:100">家庭住址</th>
		<th data-options="field:'phone',width:100">手机号</th>
		<th data-options="field:'floorId',width:100">楼号</th>
		<th data-options="field:'unitId',width:100">单元号</th>
		<th data-options="field:'roomId',width:100">房间号</th>
		<th data-options="field:'houseId',width:100">房产编号</th>
		<th data-options="field:'deleted',width:100,
					formatter: function (deleted, row, index) {
			       return deletedState(deleted); <!--value就是数据库具体的值-->
			    }">使用状态</th>
	</tr>
	</thead>
</table>
<div id="tb" style="padding:2px 5px;">
	用户账号：<input id="platForm" style="width:110px">
	用户姓名：<input id="userName" style="width:110px">
	使用状态:
	<select id="deleted" class="easyui-combobox" panelHeight="auto" style="width:100px">
		<option value="0">全部</option>
		<option value="1">使用中</option>
	</select>
	<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="searchA()">Search</a>
	<a href="#" class="easyui-linkbutton" iconCls="icon-add" onclick="add()" style="float:right">添加</a>
</div>

<div id="approve" class="easyui-window" title="编辑" data-options="iconCls:'icon-save'" style="width:500px;height:400px;padding:10px;">
	<div class="easyui-panel" title="住户编辑" style="width:100%;max-width:400px;padding:30px 60px;">
		<form id="update" method="post">
			<div style="margin-bottom:20px">
				<input class="easyui-textbox" name="userId" style="width:100%" data-options="label:'用户id:',required:false" readonly="readonly">
			</div>
			<div style="margin-bottom:20px">
				<input class="easyui-textbox" name="platForm" style="width:100%" data-options="label:'用户账号:',required:false" readonly="readonly">
			</div>
			<div style="margin-bottom:20px">
				<input class="easyui-textbox" name="userName" style="width:100%" data-options="label:'用户姓名:',required:false">
			</div>
			<div style="margin-bottom:20px">
				<input class="easyui-textbox" name="password" style="width:100%" data-options="label:'用户密码:',required:false">
			</div>
			<div style="margin-bottom:20px">
				<input class="easyui-textbox" name="sex" style="width:100%" data-options="label:'性别:',required:false">
			</div>
			<div style="margin-bottom:20px">
				<input class="easyui-textbox" name="address" style="width:100%" data-options="label:'家庭住址:',required:false">
			</div>
			<div style="margin-bottom:20px">
				<input class="easyui-textbox" name="phone" style="width:100%" data-options="label:'手机号:',required:false">
			</div>
			<div style="margin-bottom:20px">
				<input class="easyui-textbox" name="floorId" style="width:100%" data-options="label:'楼号:',required:false">
			</div>
			<div style="margin-bottom:20px">
				<input class="easyui-textbox" name="unitId" style="width:100%" data-options="label:'单元号:',required:false">
			</div>
			<div style="margin-bottom:20px">
				<input class="easyui-textbox" name="roomId" style="width:100%" data-options="label:'房间号:',required:false">
			</div>
			<div style="margin-bottom:20px">
				<input class="easyui-textbox" name="houseId" style="width:100%" data-options="label:'房产编号:',required:false">
			</div>
			<div style="margin-bottom:20px">
				<select name="sign" class="easyui-combobox" panelHeight="auto" style="width:180px">
					<option value="1">修改资料</option>
					<option value="0">停用</option>
					<option value="2">启用</option>
				</select>
			</div>
		</form>
		<div style="text-align:center;padding:5px 0">
			<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()" style="width:80px">Submit</a>
		</div>
	</div>
</div>

<div id="addForm" class="easyui-window" title="添加用户" data-options="iconCls:'icon-save'" style="width:500px;height:400px;padding:10px;">
	<div class="easyui-panel" title="" style="width:100%;max-width:400px;padding:30px 60px;">
		<form id="add" method="post">
			<div style="margin-bottom:20px">
				<input class="easyui-textbox" id="addPlatForm" style="width:100%" data-options="label:'用户账号:',required:true">
			</div>
			<div style="margin-bottom:20px">
				<input class="easyui-textbox" id="addUserName" style="width:100%" data-options="label:'用户姓名:',required:true">
			</div>
			<div style="margin-bottom:20px">
				<input class="easyui-textbox" id="addPassword" style="width:100%" data-options="label:'用户密码:',required:true">
			</div>
		</form>
		<div style="text-align:center;padding:5px 0">
			<a href="javascript:void(0)" class="easyui-linkbutton" onclick="addUser()" style="width:80px">Submit</a>
		</div>
	</div>
</div>
</body>
<script type="text/javascript">
	$(function(){
		searchA();
	})
	function searchA(){
		var platForm = $('#platForm').val();
		var userName = $('#userName').val();
		var deleted = $('#deleted').val();
		var data = {
				platForm:platForm,
				userName:userName,
				deleted:deleted
		};
		var pager = $('#dg').datagrid({
			queryParams: data,
			//双击事件
			onDblClickRow :function(rowIndex,rowData){
					getSelected()
				}
		}).datagrid('getPager');	// get the pager of datagrid
		pager.pagination({
			buttons:[{
				iconCls:'icon-edit',
				handler:function(){
					getSelected();
				}
			}]
		});
		pager.pagination().find('a.l-btn').tooltip({
			content: function(){
				var cc = $(this).find('span.l-btn-icon').attr('class').split(' ');
				var icon = cc[1].split('-')[1];
				return icon + ' page';
			}
		});
		$('#approve').window('close');
		$('#addForm').window('close');
	}

	function getSelected(){
		var row = $('#dg').datagrid('getSelected');
		if (row){
			$('#approve').window('open');
			$('#update').form('load',{
				userId:row.userId,
				platForm:row.platForm,
				userName:row.userName,
				password:"",
				sex:row.sex,
				address:row.address,
				phone:row.phone,
				floorId:row.floorId,
				unitId:row.unitId,
				roomId:row.roomId,
				houseId:row.houseId
			});
		}
	}
	function submitForm(){
		var id = $('#id').val();
		var data = {
			id: id
		};
		$('#update').form('submit', {
			url: "/manage/user/update",
			queryParams: data,
			onSubmit: function(){

			},
			success: function(data){
				var data = eval('(' + data + ')');
				if(data.code==10000){
					$.messager.alert('成功',"提交成功");
					var pager = $('#dg').datagrid('reload');
				}else{
					$.messager.alert('失败',data.code+"："+data.message);
				}

			},
			error: function(){
				$.messager.alert('失败',"联系管理员");
			}
		});
		$('#approve').window('close');
	}

	function add(){
		$('#addForm').window('open');
	}

	function addUser(){
		var platForm = $('#addPlatForm').val();
		var userName = $('#addUserName').val();
		var password = $('#addPassword').val();
		var data = {
				platForm:platForm,
				password:password,
				userName:userName,
				state:1
		};
		$('#add').form('submit', {
			url: "/manage/user/add",
			queryParams: data,
			onSubmit: function(){

			},
			success: function(data){
				var data = eval('(' + data + ')');
				if(data.code==10000){
					$.messager.alert('成功',"提交成功");
					var pager = $('#dg').datagrid('reload');
				}else{
					$.messager.alert('失败',data.code+"："+data.message);
				}

			},
			error: function(){
				$.messager.alert('失败',"联系管理员");
			}
		});
		$('#addForm').form('clear');
		$('#addForm').window('close');
	}

	function deletedState( deleted ){
		if("0" == deleted){
			return "正常";
		}else{
			return "停用";
		}

	}
	function stateState( state ){
		if("0" == state){
			return "管理员";
		}else{
			return "业主";
		}

	}
	</script>
</html>